package tech.yunjing.train.dao;

import org.springframework.data.redis.core.HashOperations;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * HashOperations工具类
 * Created by zlc on 2017/6/8
 */
@Service
public class ReceiveRedPacketHashOperations<T> {

    @Resource
    protected HashOperations<String, String, T> hashOperations;

    /**
     * 添加
     *
     * @param key    key
     * @param doamin 对象
     */
    public void put(String redisKey, String key, T doamin) {
        hashOperations.put(redisKey, key, doamin);
    }

    /**
     * 获取当前redis库下所有对象
     *
     * @param redisKey
     * @return
     */
    public List<T> getAll(String redisKey) {
        return hashOperations.values(redisKey);
    }

    /**
     * 查询查询当前redis库下所有key
     *
     * @param redisKey
     * @return
     */
    public Set<String> getKeys(String redisKey) {
        return hashOperations.keys(redisKey);
    }

    /**
     * 查询
     *
     * @param redisKey
     * @param key
     * @return
     */
    public T get(String redisKey, String key) {
        return hashOperations.get(redisKey, key);
    }

}
